'use strict';
angular.module('fs.waf').controller('waf.test.pti.fileUploadController', [ '$scope', 'FileUploader', function($scope, FileUploader) {
	var uploader = $scope.uploader = new FileUploader({
		url : '',
		alias : 'xxxFile',
		// queue {Array}: Items to be uploaded
		// progress {Number}: Upload queue progress percentage. Read only.
		// headers {Object}: Headers to be sent along with the files. HTML5 browsers only.
		// formData {Array}: Data to be sent along with the files
		// filters {Array}: Filters to be applied to the files before adding them to the queue. If the filter returns true the file will be added to
		// the queue
		autoUpload : true,
		method : "POST",
		removeAfterUpload : false,
		//isHTML5: false,
		// isUploading {Boolean}: true if an upload is in progress. Read only.
		//queueLimit : 1
	// withCredentials {Boolean} : enable CORS. HTML5 browsers only.
	});

	// FILTERS

	// a sync filter
	uploader.filters.push({
		name : 'syncFilter',
		fn : function(item) {
			console.log('syncFilter');
			return true;
		}
	});

	// an async filter
	uploader.filters.push({
		name : 'asyncFilter',
		fn : function(item) {
			console.log('asyncFilter');
			return true;
		}
	});

	// CALLBACKS

	uploader.onWhenAddingFileFailed = function(item, filter, options) {
		console.info('onWhenAddingFileFailed', item, filter, options);
	};
	uploader.onAfterAddingFile = function(fileItem) {
		console.info('onAfterAddingFile', fileItem);
	};
	uploader.onAfterAddingAll = function(addedFileItems) {
		console.info('onAfterAddingAll', addedFileItems);
	};
	uploader.onBeforeUploadItem = function(item) {
		console.info('onBeforeUploadItem', item);
	};
	uploader.onProgressItem = function(fileItem, progress) {
		console.info('onProgressItem', fileItem, progress);
	};
	uploader.onProgressAll = function(progress) {
		console.info('onProgressAll', progress);
	};
	uploader.onSuccessItem = function(fileItem, response, status, headers) {
		console.info('onSuccessItem', fileItem, response, status, headers);
	};
	uploader.onErrorItem = function(fileItem, response, status, headers) {
		console.info('onErrorItem', fileItem, response, status, headers);
	};
	uploader.onCancelItem = function(fileItem, response, status, headers) {
		console.info('onCancelItem', fileItem, response, status, headers);
	};
	uploader.onCompleteItem = function(fileItem, response, status, headers) {
		console.info('onCompleteItem', fileItem, response, status, headers);
	};
	uploader.onCompleteAll = function() {
		console.info('onCompleteAll');
	};
} ]);